package com.app.bimo.module_bookrack.mvp.persenter;


import com.app.bimo.commonbusiness.mvp.BasePresenter;
import com.app.bimo.commonbusiness.network.RxObservableUtil;
import com.app.bimo.commonbusiness.util.Constant;
import com.app.bimo.commonbusiness.util.DataUtil;
import com.app.bimo.commonbusiness.util.RxBus;
import com.app.bimo.library_db.UserData;
import com.app.bimo.module_bookrack.mvp.constract.Bookrack_FindContract;

public class Bookrack_FindPresenter extends BasePresenter<Bookrack_FindContract.Model, Bookrack_FindContract.View> {
    public Bookrack_FindPresenter(Bookrack_FindContract.Model model, Bookrack_FindContract.View rootView) {
        super(model, rootView);
    }

    public void requestFromModel(int channel, int page) {
        RxObservableUtil.subscribe(mModel.getFind(channel, page)
                , bindCustomLifecycle(true), bookStoreDataList -> {
                    // 处理数据 直接获取到List<JavaBean> carBeans

                    /**
                     * 断网后点击重试  需要dialog  获取数据成功后 消失
                     */
                    mRootView.hideDialogLoading();
                    mRootView.findDataNotify(bookStoreDataList);

                }, e -> {
                    mRootView.hideLoading();
                    mRootView.showError();
                });


    }

    public void addObservable() {
        toObservableSticky(UserData.class, userData -> {
            RxBus.getInstance().removeStickyEvent(UserData.class);
        });

    }

    /**
     * 分享的第三方途径，1朋友圈 2微信 3QQ 4QQ空间 5微博
     *
     * @param type
     */
    public void shareReward(int type, String imei, String time) {
        String sign = Constant.sign;
        RxObservableUtil.subscribe(mModel.shareReward(type, time, DataUtil.md5(type + time + imei + sign)),
                bindCustomLoadingLifecycle(false), bookDetailData -> {
                    mRootView.shareSuccessNotify(bookDetailData);
                });
    }


}
